package com.skt.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.skt.common.annotation.Log;
import com.skt.common.core.controller.BaseController;
import com.skt.common.core.domain.AjaxResult;
import com.skt.common.enums.BusinessType;
import com.skt.manage.domain.Medicalrecords;
import com.skt.manage.service.IMedicalrecordsService;
import com.skt.common.utils.poi.ExcelUtil;
import com.skt.common.core.page.TableDataInfo;

/**
 * 患者病历Controller
 * 
 * @author ruoyi
 * @date 2025-02-22
 */
@RestController
@RequestMapping("/manage/medicalrecords")
public class MedicalrecordsController extends BaseController
{
    @Autowired
    private IMedicalrecordsService medicalrecordsService;

    /**
     * 查询患者病历列表
     */
    @PreAuthorize("@ss.hasPermi('manage:medicalrecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(Medicalrecords medicalrecords)
    {
        startPage();
        List<Medicalrecords> list = medicalrecordsService.selectMedicalrecordsList(medicalrecords);
        return getDataTable(list);
    }

    /**
     * 导出患者病历列表
     */
    @PreAuthorize("@ss.hasPermi('manage:medicalrecords:export')")
    @Log(title = "患者病历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Medicalrecords medicalrecords)
    {
        List<Medicalrecords> list = medicalrecordsService.selectMedicalrecordsList(medicalrecords);
        ExcelUtil<Medicalrecords> util = new ExcelUtil<Medicalrecords>(Medicalrecords.class);
        util.exportExcel(response, list, "患者病历数据");
    }

    /**
     * 获取患者病历详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:medicalrecords:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(medicalrecordsService.selectMedicalrecordsByRecordId(recordId));
    }

    /**
     * 新增患者病历
     */
    @PreAuthorize("@ss.hasPermi('manage:medicalrecords:add')")
    @Log(title = "患者病历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Medicalrecords medicalrecords)
    {
        return toAjax(medicalrecordsService.insertMedicalrecords(medicalrecords));
    }

    /**
     * 修改患者病历
     */
    @PreAuthorize("@ss.hasPermi('manage:medicalrecords:edit')")
    @Log(title = "患者病历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Medicalrecords medicalrecords)
    {
        return toAjax(medicalrecordsService.updateMedicalrecords(medicalrecords));
    }

    /**
     * 删除患者病历
     */
    @PreAuthorize("@ss.hasPermi('manage:medicalrecords:remove')")
    @Log(title = "患者病历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(medicalrecordsService.deleteMedicalrecordsByRecordIds(recordIds));
    }
}
